/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaPrincipal.java
 *
 * Created on Apr 7, 2011, 1:45:47 PM
 */

package petshop.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import petshop.classes.BancoDeDados;

/**
 *
 * @author arthur
 */
public class JanelaPrincipal extends javax.swing.JFrame {

    private PainelConsultaClientes painelClientes;
    private PainelConsultaProdutos painelProdutos;
    private PainelConsultaServicos painelServicos;
    private PainelConsultaVendas painelVendas;
    private PainelConsultaAnimais painelAnimais;

    /** Creates new form JanelaPrincipal */
    public JanelaPrincipal() {
        initComponents();
        this.setTitle(" Pet Store ");
        ImageIcon logo = new ImageIcon("./imagens/logo-16.gif");

        this.setIconImage(logo.getImage());

        
        painelClientes = new PainelConsultaClientes();
        painelProdutos = new PainelConsultaProdutos();
        painelServicos = new PainelConsultaServicos();
        painelVendas = new PainelConsultaVendas();
        painelAnimais = new PainelConsultaAnimais();
        
        painelSplit.setRightComponent(painelClientes);

        ImageIcon icone = new ImageIcon("logo-42.png");
        setIconImage(icone.getImage());

        configurarFonte(botaoClientes, Color.BLACK, Font.BOLD, 16);
        configurarFonte(botaoProdutos, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoServicos, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoVendas, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoAnimais, Color.BLACK, Font.PLAIN, 12);
        
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.setSize(700,450);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelSplit = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        botaoClientes = new javax.swing.JButton();
        botaoProdutos = new javax.swing.JButton();
        botaoServicos = new javax.swing.JButton();
        botaoVendas = new javax.swing.JButton();
        botaoAnimais = new javax.swing.JButton();
        MenuPricipal = new javax.swing.JMenuBar();
        MenuSistema = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        MenuItemLogout = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        VendasRelatorioMenu = new javax.swing.JMenu();
        RelatorioItemMenu = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(850, 450));

        painelSplit.setDividerLocation(170);
        painelSplit.setDividerSize(0);
        painelSplit.setMinimumSize(new java.awt.Dimension(170, 400));
        painelSplit.setPreferredSize(new java.awt.Dimension(700, 350));

        jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel1.setMinimumSize(new java.awt.Dimension(170, 400));
        jPanel1.setPreferredSize(new java.awt.Dimension(170, 400));

        botaoClientes.setText("Clientes");
        botaoClientes.setPreferredSize(new java.awt.Dimension(150, 40));
        botaoClientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clicarBotaoClientes(evt);
                mudarFonte(evt);
            }
        });
        jPanel1.add(botaoClientes);

        botaoProdutos.setText("Produtos");
        botaoProdutos.setPreferredSize(new java.awt.Dimension(150, 40));
        botaoProdutos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clicarBotaoProdutos(evt);
                mudarFonte(evt);
            }
        });
        jPanel1.add(botaoProdutos);

        botaoServicos.setText("Serviços");
        botaoServicos.setPreferredSize(new java.awt.Dimension(150, 40));
        botaoServicos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clicarBotaoServicos(evt);
                mudarFonte(evt);
            }
        });
        jPanel1.add(botaoServicos);

        botaoVendas.setText("Vendas");
        botaoVendas.setPreferredSize(new java.awt.Dimension(150, 40));
        botaoVendas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clicarBotaoVendas(evt);
                mudarFonte(evt);
            }
        });
        jPanel1.add(botaoVendas);

        botaoAnimais.setText("Animais");
        botaoAnimais.setPreferredSize(new java.awt.Dimension(150, 40));
        botaoAnimais.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                botaoAnimaismudarFonte(evt);
                botaoAnimaisclicarBotaoAnimais(evt);
            }
        });
        botaoAnimais.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAnimaisActionPerformed(evt);
            }
        });
        jPanel1.add(botaoAnimais);

        painelSplit.setLeftComponent(jPanel1);

        getContentPane().add(painelSplit, java.awt.BorderLayout.CENTER);

        MenuSistema.setText("Sistema");

        jMenuItem2.setText("Cadastrar Usuário");
        jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuItem2MouseClicked(evt);
            }
        });
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        MenuSistema.add(jMenuItem2);

        MenuItemLogout.setText("Logout");
        MenuItemLogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clicarMenuLogout(evt);
            }
        });
        MenuSistema.add(MenuItemLogout);

        jMenuItem1.setText("Sair");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        MenuSistema.add(jMenuItem1);

        MenuPricipal.add(MenuSistema);

        jMenu1.setText("Relatórios");

        jMenu2.setText("Produtos");

        jMenuItem3.setText("Relatório de estoque");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenu1.add(jMenu2);

        VendasRelatorioMenu.setText("Vendas");

        RelatorioItemMenu.setText("Mensal");
        RelatorioItemMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RelatorioItemMenuActionPerformed(evt);
            }
        });
        VendasRelatorioMenu.add(RelatorioItemMenu);

        jMenu1.add(VendasRelatorioMenu);

        MenuPricipal.add(jMenu1);

        setJMenuBar(MenuPricipal);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void clicarBotaoProdutos(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicarBotaoProdutos
        if(!painelSplit.getRightComponent().equals(painelProdutos)){
            painelSplit.setRightComponent(painelProdutos);
        }
}//GEN-LAST:event_clicarBotaoProdutos

    private void clicarBotaoServicos(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicarBotaoServicos
        if(!painelSplit.getRightComponent().equals(painelServicos)){
            painelSplit.setRightComponent(painelServicos);
        }
    }//GEN-LAST:event_clicarBotaoServicos

    private void clicarBotaoVendas(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicarBotaoVendas
        if(!painelSplit.getRightComponent().equals(painelVendas)){
            painelSplit.setRightComponent(painelVendas);
        }
    }//GEN-LAST:event_clicarBotaoVendas

    private void clicarMenuLogout(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clicarMenuLogout
        int resp = JOptionPane.showConfirmDialog(this, "Tem certeza que deseja fazer logout?", "Logout", JOptionPane.YES_NO_OPTION);

        if(resp == JOptionPane.YES_OPTION){
            this.dispose();
            JanelaLogin janela = new JanelaLogin();

            //JanelaPrincipal janela = new JanelaPrincipal();

            // Get the size of the screen
            Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

            // Determine the new location of the window
            int w = janela.getSize().width;
            int h = janela.getSize().height;
            int x = (dim.width-w)/2;
            int y = (dim.height-h)/2;

            // Move the window
            janela.setLocation(x, y);
            janela.setVisible(true);

        }
    }//GEN-LAST:event_clicarMenuLogout

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        int resp = JOptionPane.showConfirmDialog(this, "Tem certeza que deseja sair do programa?", "Sair", JOptionPane.YES_NO_OPTION);

        if(resp == JOptionPane.YES_OPTION){
            try {
                BancoDeDados.connection.close();
            } catch (SQLException ex) {
                Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }

            System.exit(0);
        }
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void mudarFonte(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mudarFonte
        configurarFonte(botaoClientes, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoProdutos, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoServicos, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoVendas, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoAnimais, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(evt.getComponent(), Color.BLACK, Font.BOLD, 16);
    }//GEN-LAST:event_mudarFonte

    private void clicarBotaoClientes(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicarBotaoClientes
        if(!painelSplit.getRightComponent().equals(painelClientes)){
            painelSplit.setRightComponent(painelClientes);
        }
    }//GEN-LAST:event_clicarBotaoClientes

    private void jMenuItem2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem2MouseClicked
        JanelaUsuario janela = new JanelaUsuario(TipoJanela.CADASTRO, null);
        janela.setModalityType(java.awt.Dialog.DEFAULT_MODALITY_TYPE);
        janela.setModal(true);
        janela.setVisible(true);
    }//GEN-LAST:event_jMenuItem2MouseClicked

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        JanelaUsuario janela = new JanelaUsuario(TipoJanela.CADASTRO, null);
        janela.setModalityType(java.awt.Dialog.DEFAULT_MODALITY_TYPE);
        janela.setModal(true);
        janela.setVisible(true);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
        JanelaQtdEstoque estoque = new JanelaQtdEstoque();
        estoque.setVisible(true);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void RelatorioItemMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RelatorioItemMenuActionPerformed
        // TODO add your handling code here:
        JanelaRelatorioVendas vendas = new JanelaRelatorioVendas();
        vendas.setVisible(true);
    }//GEN-LAST:event_RelatorioItemMenuActionPerformed

    private void botaoAnimaismudarFonte(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botaoAnimaismudarFonte
        configurarFonte(botaoClientes, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoProdutos, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoServicos, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoVendas, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoAnimais, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(evt.getComponent(), Color.BLACK, Font.BOLD, 16);
}//GEN-LAST:event_botaoAnimaismudarFonte

    private void botaoAnimaisclicarBotaoAnimais(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botaoAnimaisclicarBotaoAnimais
        if(!painelSplit.getRightComponent().equals(painelAnimais)){
            painelSplit.setRightComponent(painelAnimais);
        }
}//GEN-LAST:event_botaoAnimaisclicarBotaoAnimais

    private void botaoAnimaisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAnimaisActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_botaoAnimaisActionPerformed
    private void clicarBotaoAnimais(java.awt.event.MouseEvent evt) {                                    
         if(!painelSplit.getRightComponent().equals(painelAnimais)){
            painelSplit.setRightComponent(painelAnimais);
        }
    }  
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JanelaPrincipal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem MenuItemLogout;
    private javax.swing.JMenuBar MenuPricipal;
    private javax.swing.JMenu MenuSistema;
    private javax.swing.JMenuItem RelatorioItemMenu;
    private javax.swing.JMenu VendasRelatorioMenu;
    private javax.swing.JButton botaoAnimais;
    private javax.swing.JButton botaoClientes;
    private javax.swing.JButton botaoProdutos;
    private javax.swing.JButton botaoServicos;
    private javax.swing.JButton botaoVendas;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSplitPane painelSplit;
    // End of variables declaration//GEN-END:variables
      
    
    private void configurarFonte(java.awt.Component c, Color cor, int estilo, int tamanhoFonte){
        c.setForeground(cor);
        c.setFont(new Font("Tahoma", estilo, tamanhoFonte));
    }

    private void setIconImage(ImageIcon imageIcon) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
